//
//  Level2.h
//  GameProject
//
//  Created by Blair Trusler on 01/12/2011.
//  Copyright (c) 2011 Blair Trusler. All rights reserved.
//

#import "GameHeader.h"
#include <sys/types.h>
#include <sys/sysctl.h>

@interface Level2Scene : CCScene{
}
@end

@class EnemySprite;
@class PlayerSprite;
@class PathNode;

#define TILE_OPEN 0
#define TILE_WALL 1
#define TILE_START 2
#define TILE_FINISH 3
#define TILE_MARKED 4
#define TILE_TAG 100
#define TILE_ROWS_lv2 50  
#define TILE_COLS_lv2 50  

@interface Level2 : CCLayer{
//    BOOL calcPatrolPath;
    BOOL calcPatrolPath2;
    int calcPatrolPath;
    
    CCTMXTiledMap *_tileMap;
    CCTMXLayer *_background; 
    CCTMXLayer *_foreground;
    CCTMXLayer *_meta;
    CCSprite *_player;
    CCSpriteBatchNode *_playerSprite;
    HUD *_hud;
    
//    CCSpotLight *spotLight;
//    CCRenderTexture *renderLayer;


    int audioCounter;
    
    CGPoint enemySpawnPos1;
    CGPoint enemySpawnPos2;
    
    int patrolXPos[50];
    int patrolYPos[50];
    
    int patrolPointX1;
    int patrolPointY1;
    int patrolPointX2;
    int patrolPointY2;
    int patrolPointX1_enemy3,patrolPointY1_enemy3;
    int patrolPointX1_enemy4,patrolPointY1_enemy4;
    int patrolPointX1_enemy5,patrolPointY1_enemy5;

    CGPoint enemy2_patrolPoint1;
    CGPoint enemy2_patrolPoint2;
    
    CGPoint enemy3_patrolPoint1;
    
    int patrolCounter;
    
    BOOL patrolPathsToGenerate; 
    int pathCheck;
        
    unsigned char tileArray[TILE_COLS_lv2][TILE_ROWS_lv2]; 
    
	NSMutableArray *pointerToOpenList;
    
    int startX, startY, endX, endY; //Start/End points of path between Player and chasing Enemy Sprite 1
    
    int startPatrolX, startPatrolY, endPatrolX, endPatrolY; //Patrol paths for Enemy Sprite 2
    int startPatrolX_enemy3, startPatrolY_enemy3, endPatrolX_enemy3, endPatrolY_enemy3;
    int startPatrolX_enemy4,startPatrolY_enemy4,endPatrolX_enemy4,endPatrolY_enemy4;
    int startPatrolX_enemy5,startPatrolY_enemy5,endPatrolX_enemy5,endPatrolY_enemy5;
    
    NSMutableArray *movementPathX, *movementPathY;
    
    NSMutableArray *patrolPathX1, *patrolPathY1;
    NSMutableArray *patrolPathX2, *patrolPathY2;
    
    NSMutableArray *patrolPathX1_enemy3, *patrolPathY1_enemy3;
    NSMutableArray *patrolPathX1_enemy4, *patrolPathY1_enemy4;
    NSMutableArray *patrolPathX1_enemy5, *patrolPathY1_enemy5;

    BOOL allowDiags;
}

@property (nonatomic, retain) CCTMXTiledMap *tileMap;
@property (nonatomic, retain) CCTMXLayer *background;
@property (nonatomic, retain) CCTMXLayer *foreground;
@property (nonatomic, retain) CCTMXLayer *meta;
@property (nonatomic, retain) CCSprite *player;
@property (nonatomic, retain) CCSpriteBatchNode *playerSprite;
@property (nonatomic, retain) HUD *hud;
@property BOOL allowDiags;
@property int startX;
@property int startY;
@property int endX;
@property int endY;
@property int startPatrolX;
@property int startPatrolY;
@property int endPatrolX;
@property int endPatrolY;
@property int startPatrolX_enemy3;
@property int startPatrolY_enemy3;
@property int endPatrolX_enemy3;
@property int endPatrolY_enemy3;
@property int startPatrolX_enemy4;
@property int startPatrolY_enemy4;
@property int endPatrolX_enemy4;
@property int endPatrolY_enemy4;
@property int startPatrolX_enemy5;
@property int startPatrolY_enemy5;
@property int endPatrolX_enemy5;
@property int endPatrolY_enemy5;

@property int patrolPointX1;
@property int patrolPointY1;
@property int patrolPointX2;
@property int patrolPointY2;

-(PathNode *)lowestCostNodeInArray:(NSMutableArray*)openList1;

-(void) createPath:(ccTime)dt;
-(void) clear:(id) sender;
-(BOOL) isWall:(CGPoint) position;
-(BOOL) findPath:(int)sx :(int)sy :(int)ex :(int)ey;
-(void) flipTileArray;
-(CGPoint) tilePositionForCoord:(CGPoint) coord;

-(void)moveOnPath;

+(id) scene;

+(NSString*) getDefaultLevel; 
-(void) loadMap;

-(void)setViewpointCenter:(CGPoint) position;
-(CGPoint)tileCoordForPosition:(CGPoint)position;
-(CGPoint)positionForTileCoord:(CGPoint)tileCoord;


@end
